package com.sfeir.poc.portal.gui.client.dnd;

import com.allen_sauer.gwt.dnd.client.drop.IndexedDropController;
import com.google.gwt.user.client.ui.IndexedPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * IndexedDropController that disallows dropping after the last child, which is
 * assumed to be dummy spacer widget preventing parent collapse.
 */
public class NoInsertAtEndIndexedDropController extends IndexedDropController {

	private IndexedPanel dropTarget;

	public NoInsertAtEndIndexedDropController(IndexedPanel dropTarget) {
		super(dropTarget);
		this.dropTarget = dropTarget;
	}

	@Override
	protected void insert(Widget widget, int beforeIndex) {
		if (beforeIndex == dropTarget.getWidgetCount()) {
			beforeIndex--;
		}
		super.insert(widget, beforeIndex);
	}
}
